﻿using BBICMS.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BBICMS.WebUI.Controllers
{
    public class PageController : BaseController
    {
        // GET: Page
        public ActionResult Details(int id)
        {
            return View();
        }

       // [Route("{culture}/{seoName}")]
       // [Route(Name = "PageRoute")]        
        public ActionResult DetailsSEO(string seoName)
        {
            var page = _unit.Pages.FindBy(p => p.SeoName.Equals(seoName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
            if (page == null)           
                return HttpNotFound();

            var lang = LanguageHelper.GetCurrentCulture();
            var pageLang = _unit.PageLangs.GetFirstOrDefault(p => p.PageId == page.Id && p.CultureName.Equals(lang, StringComparison.InvariantCultureIgnoreCase),p=>p.Page);
            if(pageLang == null)
            {
                pageLang = _unit.PageLangs.GetFirstOrDefault(p => p.PageId == page.Id, p => p.Page);
                return View(pageLang);
            }
            else
            {
                return View(pageLang);
            }            
        }
    }
}